package com.mf.pte.pojo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class LevelList {

    private List<MyComponentLevel> levels;

    public LevelList(List<MyComponent> components) {
        this.levels = new ArrayList<>();
        HashMap<String, MyComponent> temp = new HashMap<>();
        for (int i = 0; i < components.size(); i++) {
            MyComponent component = components.get(i);
            int currentLevel = component.getLevel();
            MyComponentLevel componentLevel = getLevel(currentLevel);
            componentLevel.addMyComponentInThisLevel(component);
        }
    }

    public MyComponentLevel getLevel(int i ){
        while (levels.size()<=i){
            levels.add(new MyComponentLevel());
        }
        return levels.get(i);
    }

    public MyComponent getItemInSomeLevelByDrawName(String drawName,int level){
        if(level>=levels.size()){
            throw new RuntimeException("没有第"+level+"层");
        }
        return levels.get(level).getByDrawNumber(drawName);
    }


    public void print(){
//        Item product = getProduct();
//        if(product==null){
//            throw new RuntimeException("BOM解析失败，没有产品总成");
//        }
//        product.print(0);
    }

}
